package cn.example.zjgsu.controller;

import cn.example.zjgsu.pojo.FoodRecord;
import cn.example.zjgsu.pojo.result.JsonData;
import cn.example.zjgsu.service.PublishPageServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author xuejiahui
 * @date 2020/3/31 -18:21
 */
@RestController
@RequestMapping({"/v1/api/publishpage"})
@Api(description = "发布接口")
public class PublishPageController {

    @Autowired
    PublishPageServer publishPageServer;

    @ApiOperation("新增普通食记")
    @PostMapping(value = "/insertcommonfoodrecord")
    public JsonData insertCommonFoodRecord(@RequestBody FoodRecord foodRecord, String userid, int cityid){
        return JsonData.success(publishPageServer.insertCommonFoodRecord(foodRecord,userid,cityid));
    }

    @ApiOperation("新增带一日计划食记")
    @PostMapping(value = "/insertplanfoodrecord")
    public JsonData insertPlanFoodRecord(@RequestParam("file")MultipartFile[] files, String title,String content,String userid, int planid, int cityid){
        try {
            return JsonData.success(publishPageServer.insertPlanFoodRecord(files,title,content,userid,planid,cityid));
        } catch (IOException e) {
            return JsonData.fail("插入食记插入失败,请重新发表");
        }
    }

    @ApiOperation("根据食记id获取详细")
    @GetMapping(value = "/seltectDetailFoodRecord")
    public JsonData seltectDetailFoodRecordById(int foodrecordid){
        return JsonData.success(publishPageServer.seltectDetailFoodRecordById(foodrecordid));
    }

    @ApiOperation("根据食记id点赞食记")
    @PostMapping(value = "/praisefoodrecord")
    public JsonData praiseFoodRecord(int foodrecordid){
        return JsonData.success(publishPageServer.praiseFoodRecord(foodrecordid));
    }

    @ApiOperation("根据食记id删除食记")
    @DeleteMapping(value = "/deltefoodrecord")
    public JsonData delteFoodRecord(int foodrecordid){
        return JsonData.success(publishPageServer.delteFoodRecord(foodrecordid));
    }

    @ApiOperation("根据计划id获取一键生成一日计划食记的内容")
    @GetMapping(value = "/oneclickfoodrecord")
    public JsonData oneClickFoodRecord(int planid){
        return JsonData.success(publishPageServer.oneClickFoodRecord(planid));
    }





}
